<?php get_partial('game/gameRepresentation'); ?>
<div class="rules_content">

	<table class="content_table">
		<colgroup style="width:*"></colgroup>		
		<colgroup style="width:80px"></colgroup>
		<colgroup style="width:90px"></colgroup>
		<colgroup style="width:210px"></colgroup>
		<colgroup style="width:160px"></colgroup>
		<tr id="header">
			<td>Nazwa zasad gry</td>
			<td>Typ</td>
			<td>Wygrywają</td>
			<td>Warunek końca meczu</td>
			<td>Data modyfikacji</td>
		</tr>
		<tr class="tr_odd">
		<td id="content_name"><?php echo image_tag('iBrowse.png',array('class'=>'option_img'))?><?php echo $rule->getName() ?></td>
		<td><?php echo $rule->getType()?'drzewo':'macierz' ?></td>
		<td><?php echo $ruleData->getWinPoints()?'większe':'mniejsze' ?></td>
		<td>do <?php echo $ruleData->getMatchEndValue() ?> 
		
<?php 


switch($ruleData->getMatchEndType())
{
	case 0:
		echo "gier";
	break;
	case 1:
		echo "punktów przewagi";
	break;
	case 2:
		echo "punktów";
	break;
	case 3:
		echo "zwycięstw";
	break;
}
 ?></td>
 <td><?php echo $rule->getUpdatedAt() ?> </td>
		</tr>
</table>

<?php if($rule->getType()==0){ ?> 
 
<?php /*
    <table class="rules_matrix_table">
		<tr>
			<td></td>
			<?php foreach($ruleData->getRows() as $row): ?>
				<td colspan="2" class="matrix_actions2 ingame_action"><img class="option_img" src="/images/iAction.png"><?php echo $row ?></td>
			<?php endforeach ?>
		</tr>
		<?php $size=$ruleData->getSize(); $j=0?>
		<?php foreach($ruleData->getCols() as $col): ?>
				<tr class="matrix_row">
					<td class="matrix_actions1 matrix_row ingame_action"><img class="option_img" src="/images/iAction.png"><?php echo $col ?></td>
					<?php for($i=0;$i<$size[0];$i++): ?>
						<?php $cell= $ruleData->getCell($i,$j)?>
						<td class="matrix_cell1 matrix_row"><span class="cell_points1"><?php echo $cell[0]?></span></td>
						<td class="matrix_cell2 matrix_row"><span class="cell_points2"><?php echo $cell[1]?></span></td>
					<?php endfor ?>
					<?php $j++ ?>
				</tr>
		<?php endforeach ?>
	</table>
<?php  ?>

</td></tr>
</table>

*/ ?>
<?php
echo generateMatrixRepresentation($ruleData,0);
?>

<?php }else{ ?>
    <div id="tree_preview">
<?php 

$treeNodes=array();
$treeNodes=$ruleData->getContent();

/* STARY KOD BEZWARTOSCIOWY :)
function generateNode(&$a,$i,$act){
	$content='';	
	$content.='<table id="tree_node'.$a[$i]->getId().'" class="tree_preview_'.($a[$i]->getType()==3?'points':'table').'">';
	$content.=generateNodeLabel($a,$i,$act);	
	$content.=generateNodeActions($a,$i,$act);
	$content.="</table>";
	return $content;
}

function generateNodeLabel(&$a,$i,$act){
	switch ($a[$i]->getType()){
		case 0:
			return '<tr id="tree_node'.$a[$i]->getId().'label"><td class="tree_preview_name" colspan="'.$a[$i]->getActions()->count().'" '.($a[$i]->getId()==$act?'style="border:2px solid black;"':'').'><img class="option_img" src="/images/iPlayer1.png">'.$a[$i]->getLabel().' &raquo;'.$a[$i]->getGroup().'&laquo;</td></tr>';
			break;
		case 1:
			return '<tr id="tree_node'.$a[$i]->getId().'label"><td class="tree_preview_name" colspan="'.$a[$i]->getActions()->count().'" '.($a[$i]->getId()==$act?'style="border:2px solid black;"':'').'><img class="option_img" src="/images/iPlayer2.png">'.$a[$i]->getLabel().' &raquo;'.$a[$i]->getGroup().'&laquo;</td></tr>';
			break;
		case 2:
			return '<tr id="tree_node'.$a[$i]->getId().'label"><td class="tree_preview_name" colspan="'.$a[$i]->getActions()->count().'"><img class="option_img" src="/images/iNature.png">N</td></tr>';
			break;
		case 3:
			return '';
			break;
	}
}

function getIdIndex(&$a,$id) {

	for($n=0;$n<count($a);$n++){
		if($id==$a[$n]->GetId()){
				return $n;
		}
	}

}

function generateNodeActions(&$a,$i,$act){ //->getLabel();	
	$content='';
	$content.='<tr id="tree_node'.$a[$i]->getId().'actions">';

	$node=$a[$i];
	
	switch ($node->getType()){
		case 0:
		case 1:
			for($x=0;$x<$node->getActions()->count();$x++){
				$action1=$node->getActions()->getRaw($x);
				$content.='<td class="tree_preview_td" id="tree_node'.$node->getId().'action'.$action1[1].'">|<br><img class="option_img" src="/images/iAction.png">'.$action1[0].'<br>|'.generateNode($a,getIdIndex($a,$action1[1]),$act).'</td>';
			}
			$content.='</tr>';
			break;

		case 2:
			for($x=0;$x<$node->getActions()->count();$x++){
				$action2=$node->getActions()->getRaw($x);
				$content.='<td class="tree_preview_td" id="tree_node'.$node->getId().'action'.$action2[2].'">|<br><img class="option_img" src="/images/iAction.png">'.$action2[0].' ('.$action2[1].')<br>|'.generateNode($a,getIdIndex($a,$action2[2]),$act).'</td>';
			}
			$content.='</tr>';
			break;

		case 3:
			$content.='<td class="tree_preview_td" id="tree_node'.$node->getId().'points1"><img class="option_img" src="/images/iPlayer1.png">'.$node->getPlayerPoints(0). '</td>';
			$content.='<td class="tree_preview_td" id="tree_node'.$node->getId().'points2"><img class="option_img" src="/images/iPlayer2.png">'.$node->getPlayerPoints(1).'</td>';
			$content.='</tr>';
			break;

	}

	return $content;	

}

echo generateNode($treeNodes,0,0);

*/


echo generateNode2($treeNodes,0,$treeNodes[0]->getId(),0); //wyswietlanie calego drzewa bez akcji
?>

<?php } ?>
</div>
</div>

<?php
/*
 * 
 * 
 * POCZATEK-GENEROWANIE MECZU
$treeNodes to tablica unserialized getContent
przy tworzeniu meczu wedlug zasad drzewa nalezy ustawic
<GAME.NODE> = $treeNodes[0]->getId(); 
$act_id = $treeNodes[0]->getId(); 

OBSŁUGA AKCJI
jak gracz wybierze akcje to nalezy pobrac id wezla wskazywanego przez akcje i ustawic jako trzeci parametr - aktywny id wezla
(w send-option od drzewa)
$index_act = getIdIndex2($treeNodes, $act_id);
$actions = $treeNodes[$index_act]->getActions();

if($treeNodes[index_act]->getType==gameRules::$TN_NATURE){
    obsluga natury czyli losowanie - uzycie funkcji losujacej co kiedys napisalem
    $act_id = $treeNodes[$treeNodes[$index_act]->getRandomId()][2];
}else{
if(<GETPARAMETER:ID> >= count($actions))  <GETPARAMETER:ID>=0; //jezeli cos jest nie tak to wybieramy pierwsza opcje zeby sie nie rozpieprzylo cos
$act_id = $actions[<GETPARAMETER:ID>][1];
}
<GAME.NODE> = $act_id;



DRUKOWANIE W GRZE
if(isFirstPlayer){
    echo generateNode2($treeNodes,0,$act_id,1);
} else {
    echo generateNode2($treeNodes,0,$act_id,2);
}



*/?>